package com.example.suuu.project.system.controller;

import com.example.suuu.project.system.entity.SuRole;
import com.example.suuu.project.system.entity.vo.RoleMenuCode;
import com.example.suuu.project.system.entity.vo.UserRoleCode;
import com.example.suuu.tools.log.LogPrint;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.example.suuu.project.system.service.impl.SuRoleServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.CrossOrigin;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import com.example.suuu.model.result.ResultVo;
import com.example.suuu.project.system.query.SuRoleQuery;

import javax.annotation.Resource;

/**
 * @desc 角色 API接口
 * @author sun
 * @date 2023-06-28
 */
@CrossOrigin
@RestController
@RequestMapping("/suRole")
@Api(value = "/suRole", tags = {"角色 API接口"})
@ApiSupport(author = "sun")
public class SuRoleController{

    @Resource
    public SuRoleServiceImpl suRoleService;


    @PostMapping("/add")
    @LogPrint("角色新增")
    @ApiOperation(value = "角色新增",notes = "角色新增")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVo add(@Validated @RequestBody SuRole u) {
        return ResultVo.ResultVoSuccess(suRoleService.add(u));
    }
    @PutMapping("/update")
    @LogPrint("角色修改")
    @ApiOperation(value = "角色修改",notes = "角色修改")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo update(@Validated @RequestBody SuRole u) {
        return ResultVo.ResultVoSuccess(suRoleService.update(u));
    }
    @DeleteMapping("/del/{id}")
    @LogPrint("角色删除")
    @ApiOperation(value = "角色删除",notes = "角色删除")
    public ResultVo del(@Validated @PathVariable(value="id") Integer id) {
        return ResultVo.ResultVoSuccess(suRoleService.del(id));
    }
    @GetMapping("/getlist")
    @LogPrint("角色查询")
    @ApiOperation(value = "角色查询",notes = "角色查询")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo get(SuRoleQuery query) {
        return ResultVo.ResultVoSuccess(suRoleService.pagVo(query));
    }
    @GetMapping("/getById/{id}")
    @LogPrint("角色id查询")
    @ApiOperation(value = "角色id查询",notes = "角色id查询")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo getById(@Validated @PathVariable(value="id") Integer id) {
        return ResultVo.ResultVoSuccess(suRoleService.getById(id));
    }


    @PostMapping("/rolemenuadd")
    @LogPrint("角色菜单表新增")
    @ApiOperation(value = "角色菜单表新增",notes = "角色菜单表新增")
    public ResultVo userroleadd(@Validated @RequestBody RoleMenuCode u) {
        return ResultVo.ResultVoSuccess(suRoleService.insertBatch(u));
    }
}